package com.chensf.studydemo.common

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.chensf.studydemo.R
import kotlinx.android.synthetic.main.view_record_audio.view.*

class AudioRecordView :FrameLayout{
    private val cancelImage:ImageView
    private val tipsTV:TextView
    private val recordBtn:AudioRecordButton
    private val waveView:View
    var listener:AudioRecordListener?=null
    set(value) {
        recordBtn.listener = value
        field = value
    }
    constructor(context: Context) : this(context, null)
    constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
    constructor(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attributeSet,
        defStyleAttr
    ){
        val view = LayoutInflater.from(context).inflate(R.layout.view_record_audio, this, true)
        cancelImage = view.cancelBtn
        tipsTV = view.tips
        recordBtn = view.recordBtn
        waveView = view.waveView
        recordBtn.setCancelBtn(cancelImage)
        recordBtn.setTipsTV(tipsTV)
        recordBtn.setWaveView(waveView)
        recordBtn.listener = this.listener
    }
}
interface AudioRecordListener {
    fun start()
    fun cancel()
    fun complete()
}